home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 1 / Macwelt DVD 1.toast / Web-Publishing / HTML-Editoren / Alpha ƒ / Tcl / Modes / sqlMode.tcl < prev    next >
Encoding:
Text File  |  2000-12-07  |  5.6 KB  |  153 lines

  1.  
  2. #############################################################################
  3. #   FILE: sql.tcl
  4. #----------------------------------------------------------------------------
  5. # AUTHOR:     Joel D. Elkins
  6. #     of      New Media, Inc.
  7. #             200 South Meridian, Ste. 220
  8. #             Indianapolis, IN 46225
  9. #
  10. # internet:   jdelkins@iquest.net  (preferred)
  11. # compuserve: 72531,314
  12. # AOL:        jdelkins
  13. #
  14. #   Copyright © 1994-1995 by Joel D. Elkins
  15. #   All rights reserved.
  16. #############################################################################
  17. #
  18. #  Alpha mode for SQL and Oracle's PL/SQL programming language
  19. #  Converts SQL and PL/SQL keywords to uppercase on the fly and colorizes
  20. #
  21. #############################################################################
  22. # HISTORY
  23. #                  
  24. # modified who rev reason
  25. # -------- --- --- ------ 
  26.  #  2000-12-07 DWH 1.1.2 updated help text
  27. # 7/29/94  JDE 1.0 Original 
  28. # 2/8/95   JDE 1.1 Added electUpper for tab, cr, and ';'
  29. #############################################################################
  30.  
  31. alpha::mode SQL 1.1.2 dummySQL {*.sql *.SQL *.pkg} electricSemicolon {
  32. } help {
  33.     SQL Mode for SQL and Oracle's PL/SQL programming language converts
  34.     SQL and PL/SQL keywords to uppercase on the fly and colorizes. 
  35.     Automatic file marking with the Marks Menu is supported.
  36.     
  37.     Click on this "SQL Example.sql" link for an example syntax file.
  38.     
  39.     Oracle maintains a faq <http://www.orafaq.org/> with more 
  40.     information about SQL.
  41. }
  42.  
  43. proc dummySQL {} {}
  44.  
  45. #############################################################################
  46. # PL/SQL mode by Joel D. Elkins
  47. #############################################################################
  48.  
  49. newPref    v    wordBreak        {(\$)?\w+}    SQL
  50. newPref    v    prefixString        {--}    SQL
  51. newPref    f    wordWrap        {0}    SQL
  52. newPref    v    funcExpr        {(PROCEDURE|FUNCTION)[ \t]+(\w+)}    SQL
  53. newPref    v    wordBreakPreface    {[^a-zA-Z0-9_\$]} SQL
  54. # Set this preference to automatically upcase command names as you type.
  55. newPref f upcaseCommands {1} SQL
  56.  
  57. Bind '\ ' {sql_electUpper "\ "} "SQL"
  58. Bind '\t' {sql_electUpper "\t"} "SQL"
  59. Bind '\r' {sql_electUpper "\r"} "SQL"
  60. Bind '\;' {sql_electUpper "\;"} "SQL"
  61.  
  62.  
  63. set sqlKeywords {
  64.     ABORT ACCEPT ACCESS ALTER AND ARRAY ARRAYLEN AS ASSERT AT AVG BEGIN BETWEEN BODY
  65.     CASE COLUMNS COMMIT CONSTANT COUNT CREATE CURSOR DECLARE DEFAULT DEFINITION
  66.     DELETE DESC DISPOSE DISTINCT DO DROP ELSE ELSIF END ENTRY EXCEPTION EXISTS EXIT
  67.     FALSE FETCH FOR FROM FUNCTION GOTO IF IN INSERT INTERSECT INTO IS LIKE LOOP MAX MIN
  68.     MINUS MOD NEW OF ON OPEN OR OUT PACKAGE PARTITION POSITIVE PRAGMA PRIVATE
  69.     PROCEDURE PUBLIC RANGE RECORD REM REPLACE RETURN ROLLBACK ROWTYPE RUN SAVEPOINT
  70.     SELECT SET SIZE START STDDEV SUM THEN TO TYPE UNION UNIQUE UPDATE USE VALUES
  71.     VARIANCE WHEN WHERE WHILE WITH XOR
  72. }
  73. ###    Just colorize uppercase keywords
  74. #    abort accept access alter and array arraylen as assert at avg begin between body
  75. #    case columns commit constant count create cursor declare default definition
  76. #    delete desc dispose distinct do drop else elsif end entry exception exists exit
  77. #    false fetch for from function goto if in insert intersect into is like loop max min
  78. #    minus mod new of on open or out package partition positive pragma private
  79. #    procedure public range record rem replace return rollback rowtype run savepoint
  80. #    select set size start stddev sum then to type union unique update use values
  81. #    variance when where while with xor
  82. ###
  83. regModeKeywords -e {--} -b {/*} {*/} -c red -k blue SQL $sqlKeywords
  84. unset sqlKeywords
  85. #================================================================================
  86.  
  87. catch {unset plSqlKeywords}
  88.  
  89. lappend plSqlKeywords \
  90.   abort accept access alter and array arraylen as assert at avg begin between body \
  91.   case columns commit constant count create cursor declare default definition \
  92.   delete desc dispose distinct do drop else elsif end entry exception exists exit \
  93.   false fetch for from function goto if in insert intersect into is like loop max min \
  94.   minus mod new of on open or out package partition positive pragma private \
  95.   procedure public range record rem replace return rollback rowtype run savepoint \
  96.   select set size start stddev sum then to type union unique update use values \
  97.   variance when where while with xor
  98.  
  99.  
  100. set firstUpcase 1
  101. proc sql_electUpper {char} {
  102.     global SQLmodeVars plSqlKeywords firstUpcase
  103.  
  104.     set a [getPos]
  105.     backwardWord
  106.     set b [getPos]
  107.  
  108.     #make sure we're not in a comment
  109.     beginningOfLine
  110.     set commentSearch {(^[ \t]*rem[ \t]+)|(^[ \t]*REM[ \t]+)|--}
  111.     if {[catch {search -s -r 1 -f 1 -l $b -- $commentSearch [getPos]}] != 0} {
  112.     #if not, make the word uppercase if it's a keyword
  113.     set cmd [getText $b $a]
  114.     goto $b
  115.     if {$SQLmodeVars(upcaseCommands) && \
  116.       [lsearch -exact $plSqlKeywords [string tolower $cmd]] >= 0} {
  117.         upcaseWord
  118.         if {$firstUpcase} {
  119.         set firstUpcase 0
  120.         set messageText "Unset the \"upcaseCommands\" preference\
  121.           to disable automatic upcasing."
  122.         } else {
  123.         set messageText ""
  124.         }
  125.     }
  126.     }
  127.     goto $a
  128.     if {0 == [string compare $char "\r"]} {
  129.     bind::CarriageReturn
  130.     } else {
  131.     insertText $char
  132.     }
  133.     message $messageText
  134. }
  135.  
  136. proc SQL::MarkFile {} {
  137.     global SQLmodeVars
  138.     set pos [minPos]
  139.     while {![catch {search -s -f 1 -r 1 -m 0 -i 1 $SQLmodeVars(funcExpr) $pos} res]} {
  140.     set start [lindex $res 0]
  141.     set end [lindex $res 1]
  142.     set text [lindex [getText $start $end] 1]
  143.     set pos $end
  144.     set inds($text) "$start $end"
  145.     }
  146.     
  147.     if {[info exists inds]} {
  148.     foreach f [lsort [array names inds]] {
  149.         setNamedMark $f [lineStart [pos::math [lineStart [lindex $inds($f) 0]] - 1]] [lindex $inds($f) 0] [lindex $inds($f) 1]
  150.     }
  151.     }
  152. }
  153.